<?php
namespace app\websocket\listener;

class SwooleWebsocketMessage{
    public function handle($frame)
    {
        // {"to":"2.1","event":"chat","info":"hello 3"}

        $data = json_decode($frame->data, true);
        $sw = app("think\swoole\Websocket");

        $sw->push($sw->getSender()); // 推送给自己
        $sw->to($data['to'])->push($frame->data); // 向指定客户端推送消息
    }
}